package com.beimi.net;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.beimi.game.service.GameService;
import com.beimi.room.RoomPlayer;
import com.beimi.room.RoomPlayerMgr;
import com.corundumstudio.socketio.AckRequest;
import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.listener.DataListener;

public class AbstractRoomCmd implements DataListener<String>  {
	
    protected static final Logger LOG = LoggerFactory.getLogger(AbstractRoomCmd.class);
    
    protected RoomPlayerMgr matchPlayerMgr;

	protected GameService gameService;
	
	public void setGameService(GameService gameService) {
		this.gameService = gameService;
	}
	
	public void setMatchPlayerMgr(RoomPlayerMgr matchPlayerMgr) {
		this.matchPlayerMgr = matchPlayerMgr;
	}
    
	public void execute(RoomPlayer player, String data){
		LOG.warn("unimplement {}", data);
	}

	public void execute(SocketIOClient client, String data){
		LOG.warn("unimplement {}", data);
	}

	@Override
	public void onData(SocketIOClient client, String data, AckRequest ackSender) throws Exception {
		RoomPlayer player = matchPlayerMgr.getPlayer(client.getSessionId().toString());
		if (player == null) {
			execute(client, data);
		}
		else {
			execute(player, data);
		}
	}
}
